package zbu.eb.dao;
import zbu.eb.db.ConnectionMS;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class AdminDaoImpl implements AdminDao {
    /*若返回1密码正确
    返回2密码错误
    返回3没有此用户*/
    @Override
    public int login(String name,String password) throws SQLException, ClassNotFoundException {
        int flag = 0;
        Connection conn = ConnectionMS.getConnection();//获得连接
        String sql = "select password from admininfo where name=?";
        PreparedStatement psmt = conn.prepareStatement(sql);//预编译sql语句
        psmt.setString(1,name);//设置参数
        ResultSet rs =psmt.executeQuery();//执行
        if (rs.next()) {
            if (password.equals(rs.getString("password"))) {
                flag = 1;
            } else {
                flag = 2;
            }
        } else {
            flag = 3;
        }
        rs.close();
        psmt.close();
        conn.close();
        return flag;
    }
}
